package JDBC;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Set;

public class JDBCDemo10 {
    public static void main(String[] args) {
    UserinfoInsert userinfoInsert=InputUtil.getInputObject(new UserinfoInsert());

        try (Connection conn=DBUtil.getConnection();){
            String sql="SELECT username,password,nickname,age " +
                    "FROM userinfo " +
                    "WHERE username=? AND password=? ";
            PreparedStatement ps=conn.prepareStatement(sql);
            ps.setString(1,userinfoInsert.getUsername());
            ps.setString(2,userinfoInsert.getPassword());
            ResultSet rs=ps.executeQuery();
            if(rs.next()){
                String nickname=rs.getString("nickname");
                System.out.println("登录成功："+nickname);
                System.out.println("您的名字是："+userinfoInsert.getUsername()+"您的密码是："+userinfoInsert.getPassword());
            }else {
                System.out.println("登录失败，请重新输入");
            }












        } catch (SQLException e) {
            throw new RuntimeException(e);
        }



    }
}
